package Demo1;

class Mythread extends Thread {
    public void run() {
        while(true) {
            System.out.println("这是线程执行");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}

public class Demo1 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Mythread();
        //启动线程
        thread.start();
        while(true) {
            System.out.println("这是主线程执行");
            Thread.sleep(1000);
        }
    }
}
